var num = 1;
var pageSize = 10;

function listProtocolConfigs(pageNum, pageSize){
	$.ajax({
		url: HOST.concat("/protocolConfigs/username?username="+config.username+"&pageNum=" + pageNum + "&pageSize=" + pageSize + "&token=" + config.token),
		type: "GET",
		success: function(datas){
			checkLogin(datas);
			console.log(datas);
			addContent(datas);
		},
		error: function(){
		    console.log("请求配置列表错误！");
		},
		dataType: "json",
	});
}

function addContent(res){
	//查询成功
	if(res.meta.state==="success") {
		var list=res.data;
		if(list.length==0){
			alert("已经是最后一页!");
			num--;
		}else{
			console.log("有查询记录");
			console.log(list);
			$("#tbody").empty();
			$("#pageNum").text(num);
			for (var p in list){
				var item=list[p];//单条数据
				var _id=item["id"]+"";//将id转换为字符串
				var id=("C-"+_id.substr(6,2)+_id.substr(-6)).toUpperCase();
				var _designId=item["designId"]+"";
				var designId=("D-"+_designId.substr(6,2)+_designId.substr(-6)).toUpperCase();
				var protocolName=item["protocolName"];
				var designName=item["designName"];
				var createTime=item["createTime"];
				$("#tbody").append("<div class=\"tr clearfix border-bottom-none\">" +
					"<div class=\"td w10\">" + id+ "</div>" +
					"<div class=\"td w20\">" + designId+ "</div>" +
					"<div class=\"td w15\">" + protocolName + "</div>" +
					"<div class=\"td w20\">" + designName + " </div>" +
					"<div class=\"td w20\">" + createTime + "</div>" +
					"<div class=\"td w15\">" +
					"<div style=\"display: inline-block;\" class=\"myIcon\">" +
					"<a href=\"testConfig.html?designId="+_designId+"&configId="+_id+"&protocolName="+protocolName+"\" title=\"选择进入测试页面\"><i class=\"fa fa-check-square-o fa-lg\"></i>&nbsp;选择</a>" +
					"</div>" +
					"</div>");
			}
		}
	}else if(res.meta.message!="notlogin"){
		alert("已经是最后一页!");
		num--;
	}
}

function configLastPage(){
	if(num<=1){
		num = 1;
		alert("已经是第一页!");
		$("#pageNum").text(num);
	}else{
		num--;
		listProtocolConfigs(num,pageSize);
	}
}

function configNextPage(){
	num++;
	listProtocolConfigs(num,pageSize);
}
function configFirstPage(){
	num = 1;
	$("#pageNum").text(num);
	listProtocolConfigs(num,pageSize);
}
